package com.heima.article.controller.v1;

import com.heima.apis.article.AuthorControllerApi;
import com.heima.article.service.ApArticleService;
import com.heima.article.service.AuthorService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.*;


@RestController
@EnableDiscoveryClient
@RequestMapping("/api/v1/author")
public class AuthorController implements AuthorControllerApi {


    /**
     * 根据Id查询作者
     *
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    @Override
    public ApAuthor findById(@PathVariable("id") Integer id) {

        return authorService.getById(id);
    }

    /**
     * 根据用户id查询作者信息
     *
     * @param userId
     * @return
     */
    @Autowired
    AuthorService authorService;
    @GetMapping("/findByUserId/{userId}")
    @Override
    public ApAuthor findByUserId(@PathVariable("userId") Integer userId) {
        return authorService.findByUserId(userId);

    }

    /**
     * 保存作者
     *
     * @param apAuthor
     * @return
     */
    @PostMapping("/save")
    @Override
    public ResponseResult saveAp(@RequestBody ApAuthor apAuthor) {
        ResponseResult responseResult = authorService.saveAp(apAuthor);

        return responseResult;
    }


}
